home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Daemon / MPPatch.c < prev    next >
C/C++ Source or Header  |  1999-03-13  |  49KB  |  1,439 lines

  1. #define DEBUG
  2. #include <debug.h>
  3.  
  4. #include "MP.h"
  5. //#include "/modepro.h"
  6. #include <graphics/videocontrol.h>
  7. #include <graphics/displayinfo.h>
  8. #include "patchdata.h"
  9.  
  10.  
  11. #ifdef DEBUG
  12. #define ADD_DEBUG_CODE
  13. #endif
  14.  
  15.  
  16. void WaitForReply(struct Message *Msg);
  17.  
  18. //ULONG Colors[]={1<<16|0,~0,0,0,0};
  19.  
  20.  
  21. #define HAM_EHB_DP_KEY (HAM_KEY | 0x400 | EXTRAHALFBRITE_KEY)
  22. //                                DualPF
  23. //BOOL MPSem->Debug=FALSE;
  24.  
  25.  
  26.  
  27. /* kprintf
  28.  
  29. #ifdef ADD_DEBUG_CODE
  30.       if(MPSem->Debug)
  31.       {
  32.       }
  33. #endif
  34.  
  35. */
  36.  
  37. #define AllocOpenNode(on)  (on ? on: AllocMem(sizeof(struct OpenNode),MEMF_CLEAR|MEMF_PUBLIC))
  38.   
  39. void CatchDNode(ULONG Dest, UBYTE *Name, struct DefaultNode *SrcNode);
  40. LONG MyGetProgramName(STRPTR Buffer, LONG Len);
  41.  
  42. extern LONG InPatch;
  43. extern UBYTE   ModePro[];
  44. extern ULONG CenterAll;
  45. extern CxObj  *Broker;
  46. extern struct MsgPort *BrokerPort;
  47. extern BOOL   V39;
  48. extern BYTE   PublicSignal;
  49. extern struct MPSem *MPSem;
  50. extern struct Process  *MPTask;
  51. extern struct MsgPort *CatchPort;
  52. extern struct Screen ASM *(*OldOpenScreen)(REG __a0 struct NewScreen *,
  53.                                            REG __a6 struct IntuitionBase *);
  54. extern struct Screen ASM *(*OldOpenScreenTagList)(REG __a0 struct ExtNewScreen *ns,
  55.                                                   REG __a1 struct TagItem *taglist,
  56.                                                   REG __a6 struct IntuitionBase * );
  57. ULONG WBPromotable;
  58.  
  59. /*********************************************************************************/
  60.  
  61. struct Screen ASM __saveds  *NewOpenScreen(REG __a0 struct ExtNewScreen *ns,
  62.                                            REG __a6 struct IntuitionBase *IBase)
  63. {
  64.   struct TagItem *taglist;
  65.   struct Screen *scr;
  66.   ULONG stack1=0xc0de0000;
  67.  
  68.   DoNothing(&stack1);
  69.  
  70.   InPatch++;
  71.   taglist=0;
  72.  
  73.   if(ns)
  74.   {
  75.     if(ns->Type & NS_EXTENDED)
  76.       taglist=ns->Extension;
  77.   }
  78.   
  79.   scr=NewOpenScreenTagList(ns,taglist,IBase );
  80.   InPatch--;
  81.   return(scr);
  82. }
  83.  
  84.  
  85. struct DefaultNode CenterAllNode={0};
  86.       
  87. struct Screen ASM __saveds  *NewOpenScreenTagList(REG __a0 struct ExtNewScreen *ns,
  88.                                                   REG __a1 struct TagItem *TagList,
  89.                                                   REG __a6 struct IntuitionBase *IBase)
  90. {
  91.   struct Screen *RetScreen;
  92.   struct PatchData *pd;
  93.   struct TagItem fonttags[]= { TA_DeviceDPI , (1<<16) | 1 , TAG_DONE,0 };
  94.   ULONG stack1=0xc0de0001;
  95.  
  96.   DoNothing(&stack1);
  97.  
  98. /**** END VARS ****/
  99.  
  100.   InPatch++;
  101.  
  102.   ObtainSemaphoreShared(&MPSem->ListSem); 
  103. //  ObtainSemaphore(&MPSem->NodeSem); 
  104.  
  105. #ifdef ADD_DEBUG_CODE
  106.   if(MPSem->Debug)
  107.   {
  108.     DKP("\n");
  109.     DKP("OpenScreenX()\n");
  110.   }
  111. #endif
  112.  
  113.   if(!MPSem->Enabled && !FindTagItem(SA_ModeProNode,TagList)) // if we find SA_ModeProNode then make the screen.
  114.   {
  115.     RetScreen=OldOpenScreenTagList(ns,TagList,IBase);
  116.     
  117. DEBUG_CODE(DKP("  RetVal=%0x08lx (unpromoted 1)\n",RetScreen););
  118.     
  119.     ReleaseSemaphore(&MPSem->ListSem);
  120. //    ReleaseSemaphore(&MPSem->NodeSem);
  121.     InPatch--;
  122.     
  123.     return(RetScreen);
  124.   }
  125.   
  126.   if(pd=AllocVec(sizeof(struct PatchData),MEMF_CLEAR | MEMF_PUBLIC))
  127.   {
  128.     
  129.     pd->NullPens[0]=(~0);
  130.     pd->Promote=TRUE;
  131.     
  132. #ifdef ADD_DEBUG_CODE
  133.     if(MPSem->Debug)
  134.     {
  135.       DKP("PatchData=%8lx\n",pd);
  136.       DKP("struct NewScreen : %08lx\n",ns);
  137.      
  138.       if(ns)
  139.       {
  140.         DKP("  LeftEdge : %6ld    TopEdge  : %6ld\n", ns->LeftEdge, ns->TopEdge);
  141.         DKP("  Width    : %6ld    Height   : %6ld\n", ns->Width, ns->Height);
  142.         DKP("  Depth    : %6ld\n",ns->Depth);
  143.         DKP("  DetailPen : %3ld    BlockPen : %3ld\n",ns->DetailPen, ns->BlockPen);
  144.         DKP("  ViewMode : 0x%08lx   Type : %6ld    Font : 0x%08lx\n",ns->ViewModes, ns->Type, ns->Font);
  145.         DKP("  DefaultTitle : %s\n", (ns->DefaultTitle ? ns->DefaultTitle:""));
  146.         DKP("  Gadgets : 0x%08lx   CustomBitmap : 0x%08lx\n",ns->Gadgets, ns->CustomBitMap);
  147.         if(ns->Type & NS_EXTENDED)
  148.         {
  149.           DKP("  NOTE : NS_EXTENDED set \n");
  150.         }
  151.       }  
  152.       if(TagList)
  153.       {
  154.         DKP("  TagList:\n");
  155.         PrintTags(TagList);
  156.       }
  157.     }
  158. #endif
  159.     
  160.     /* initialize everything */
  161.  
  162.     /* 0'ed by MEMF_CLEAR
  163.     pd->DNode=NULL;  
  164.     pd->EHB_HAM=0;
  165.     pd->TagNumber=0;
  166.     pd->ScrTitle=NULL;
  167.     pd->OpenNode=NULL;
  168.     pd->HasCustomBM=pd->Changed=pd->ModeChanged=pd->SetLook3D=pd->OverscanType=pd->Interleave=0L;
  169.  
  170.     pd->SetDepth=FALSE;
  171.     pd->IsWorkbench=0;  
  172.     */
  173.     
  174.     pd->Depth=1;
  175.     pd->Width=pd->Height=pd->AutoScroll=-1;
  176.     pd->ModeID=INVALID_ID;     //                                                                           (4.56.7)
  177.     pd->ScreenPens=pd->NullPens;
  178.     pd->TaskName=FindTask(0)->tc_Node.ln_Name;
  179.   
  180.     if(MyGetProgramName(pd->CLI_Name,CLI_NAMESIZE-1)) /* Get cli program's name */
  181.     {/* This causes a hit with CED */
  182.       
  183. DEBUG_CODE(DKP("GetProgramName=\"%s\"\n",pd->CLI_Name););
  184.  
  185.       if(pd->CLI_Name[0]!=0)            /* make sure pd->CLI_Name contains something */
  186.         pd->TaskName=pd->CLI_Name;
  187.     }
  188.     
  189.     /* Initialization Done */
  190.   
  191.     /**** Extract screen info from ns and TagList ****/  
  192.     if(ns)                     
  193.     {
  194.       pd->StoredFont  =ns->Font;
  195.       pd->Width       =ns->Width;
  196.       pd->Height      =ns->Height;
  197.       pd->ModeID      =ns->ViewModes;
  198.       pd->Depth       =ns->Depth;
  199.       pd->ScrTitle    =ns->DefaultTitle;
  200.       if(ns->Type & CUSTOMBITMAP)
  201.       {
  202.         pd->HasCustomBM =ns->CustomBitMap;
  203.       }
  204.       //pd->IsWorkbench =(ns->Type & SCREENTYPE)==WBENCHSCREEN;//                                      (4.61.1)
  205.     }
  206.   
  207.     if(TagList)
  208.     {
  209.       pd->HasCustomBM=(struct BitMap *)GetTagData(SA_BitMap,    (ULONG)pd->HasCustomBM,       TagList);
  210.       pd->Width                =GetTagData(SA_Width,     pd->Width,             TagList);
  211.       pd->Height               =GetTagData(SA_Height,    pd->Height,            TagList);
  212.       pd->AutoScroll           =GetTagData(SA_AutoScroll,pd->AutoScroll,        TagList);
  213.       pd->OverscanType         =GetTagData(SA_Overscan,  pd->OverscanType,      TagList);
  214.       pd->ModeID               =GetTagData(SA_DisplayID, pd->ModeID,            TagList);
  215.       pd->Depth                =GetTagData(SA_Depth,     pd->Depth,             TagList);
  216.       pd->ScrTitle    =(UBYTE *)GetTagData(SA_Title,    (ULONG)pd->ScrTitle,    TagList);
  217.       pd->IsWorkbench         =(GetTagData(SA_Type,      pd->IsWorkbench,       TagList) & SCREENTYPE)==WBENCHSCREEN;
  218.       pd->Interleave           =GetTagData(SA_Interleaved,pd->Interleave,       TagList);
  219.       
  220.       if(pd->Tag=FindTagItem(SA_Overscan,TagList))
  221.         if(!FindTagItem(SA_DClip,TagList))
  222.           pd->OverscanType=pd->Tag->ti_Data;
  223.       
  224.       if(pd->Tag=FindTagItem(SA_Pens,TagList))
  225.       {
  226.         pd->ScreenPens=(UWORD *)(pd->Tag->ti_Data);
  227.       }
  228.     }
  229.   
  230. DEBUG_CODE(DKP("IsWorkbench=%ld\n",pd->IsWorkbench););
  231.   
  232.     if(GetDisplayInfoData(0,(UBYTE *)&pd->DispInfo,sizeof(pd->DispInfo),DTAG_DISP,pd->ModeID))
  233.     {
  234.       pd->EHB_HAM=pd->DispInfo.PropertyFlags & (DIPF_IS_DUALPF | DIPF_IS_HAM | 
  235.                                        DIPF_IS_PF2PRI | DIPF_IS_EXTRAHALFBRITE);
  236.     }
  237.  
  238.     if(!pd->ScrTitle)
  239.     {
  240.       pd->ScrTitle=GetString(MSG_ITEM_NO_NAME); /* Just in case ther isn't a pd->ScrTitle */
  241.     }
  242.  
  243.     ObtainSemaphore(&MPSem->NodeSem);    
  244.  
  245.     if(pd->DNode=(struct DefaultNode *)GetTagData(SA_ModeProNode, (ULONG)MatchDNode(pd->TaskName, pd->ScrTitle, pd->ModeID) ,TagList))
  246.     {
  247.       pd->DNode=DupDNode(pd->DNode); // Duplicate the node so we can release the node semaphore 
  248.     }
  249.     
  250.     ReleaseSemaphore(&MPSem->NodeSem);    
  251.  
  252.     if(!pd->DNode)
  253.     {
  254.       if(!pd->IsWorkbench || WBPromotable)
  255.       {
  256.         UBYTE *modename;
  257.         STRPTR dname="";
  258.         
  259.         if(MPSem->CatchScreens && MPSem->Enabled)
  260.         {
  261.           if(modename=GetModeName(pd->ModeID));
  262.           {
  263.             //if(EZReq(0,0,ModePro,GetString(MSG_NEW_SCREEN_1),GetString(MSG_NEW_SCREEN_1_BUTTONS),pd->ScrTitle,pd->TaskName,(ULONG)modename))
  264.             {
  265.               ULONG listnum=1,button;
  266.             
  267.               if(button=EZReq(0,0,ModePro,GetString(MSG_NEW_SCREEN_2),GetString(MSG_NEW_SCREEN_2_BUTTONS),(ULONG)pd->ScrTitle,(ULONG)pd->TaskName,(ULONG)modename))
  268.               {
  269.                 switch(button)
  270.                 {
  271.                   case 1:
  272.                     dname=pd->ScrTitle;
  273.                     listnum=1;
  274.                     break;
  275.                   case 2:
  276.                     dname=pd->TaskName;
  277.                     listnum=0;
  278.                     break;
  279.                   case 3:
  280.                     dname=modename;
  281.                     listnum=2;
  282.                     break;
  283.                 }
  284.                 
  285.                 if(pd->DNode=AllocDefaultNode(dname))
  286.                 {
  287.                   LONG l;
  288.                   
  289.                   pd->DNode->Type         =listnum;
  290.                   pd->DNode->Width        =pd->Width;
  291.                   pd->DNode->Height       =pd->Height;
  292.                   pd->DNode->AutoScroll   =pd->AutoScroll;
  293.                   pd->DNode->ModeSelect   =0;
  294.                   pd->DNode->ModeID       =pd->DNode->OrigDisplayID   =pd->ModeID;
  295.                   pd->DNode->OverscanType =pd->OverscanType;
  296.                   pd->DNode->Look3D       =pd->SetLook3D;
  297.                   pd->DNode->Flags        =0;//DNF_NODELETE;  /* So MPP can't delete me */
  298.                   pd->DNode->Depth        =pd->Depth;
  299.                   
  300.                   for(l=0;l<DRIPENS && pd->ScreenPens[l]!=(~0);l++)
  301.                     pd->DNode->Pens[l]=pd->ScreenPens[l];
  302.                   
  303.                   pd->DNode=ForceEdit(pd->DNode);
  304.                 }
  305.               }
  306.             }
  307.             FreeVec(modename);
  308.           }
  309.         }
  310.       }
  311.     }
  312.  
  313.     if(!pd->DNode && MPSem->CenterAll)
  314.     {
  315.       CenterAllNode.Def_Node.ln_Name="CenterAll Dummy";
  316.       CenterAllNode.CenterFlags=MPSem->CenterAll;
  317.       pd->DNode=DupDNode(&CenterAllNode);
  318.     } 
  319.   
  320.     if(pd->DNode)
  321.     {
  322.       if(pd->DNode->Flags & DNF_NEVER_PROMOTE)
  323.       {
  324.         FreeDNode(pd->DNode);
  325.         pd->DNode=0;
  326.       }
  327.       else
  328.       if(!(pd->OpenNode=AllocVec(sizeof(struct OpenNode),MEMF_CLEAR|MEMF_PUBLIC)))
  329.       {
  330.         FreeDNode(pd->DNode);
  331.         pd->DNode=0;
  332.       }
  333.       else
  334.       {
  335.         pd->OpenNode->DN=pd->DNode;
  336.       }
  337.     }
  338.       
  339. #ifdef ADD_DEBUG_CODE
  340.     if(MPSem->Debug)
  341.     {
  342.       if(pd->DNode)
  343.         PrintDefNode(pd->DNode);
  344.     }
  345. #endif
  346.     
  347.     if(!pd->DNode)
  348.     {
  349.       /* NOTE: if DNode=0 then there is no OpenNode */
  350.       RetScreen=OldOpenScreenTagList(ns,TagList,IBase);
  351.       FreeVec(pd);
  352.       
  353. DEBUG_CODE(DKP("  RetVal=%0x08lx (unpromoted 2)\n",RetScreen););
  354.       
  355.       ReleaseSemaphore(&MPSem->ListSem);
  356.  
  357.       InPatch--;
  358.       
  359.       return(RetScreen);
  360.     }
  361.   
  362.     if(!pd->IsWorkbench || WBPromotable)
  363.     {
  364.       switch(pd->DNode->ModeSelect)
  365.       {
  366.         case 0:
  367.           break;
  368.         case 1:
  369. #ifdef ADD_DEBUG_CODE
  370.         if(MPSem->Debug)
  371.         {
  372.           DKP("Promoting Monitor\n");
  373.         }
  374. #endif  
  375.           if(pd->ModeID > -1)
  376.           {
  377.           //  if(V39)
  378.             {
  379.               pd->ModeID=MyBestModeID(BIDTAG_SourceID       ,pd->ModeID,
  380.                                 BIDTAG_MonitorID      ,pd->DNode->ModeID & MONITOR_ID_MASK,
  381.                                 TAG_SKIP              ,(pd->SetDepth ? 0:1), //                        (4.56.11)
  382.                                 BIDTAG_Depth          ,pd->Depth,
  383.                                 BIDTAG_DIPFMustHave   ,pd->EHB_HAM,
  384.                                 TAG_SKIP              ,(pd->Width==-1 ? 1:0),
  385.                                 BIDTAG_DesiredWidth   ,pd->Width,
  386.                                 TAG_SKIP              ,(pd->Height==-1 ? 1:0),
  387.                                 BIDTAG_DesiredHeight  ,pd->Height,
  388.                                 TAG_DONE);
  389.             }
  390.            /* else
  391.             {
  392.               pd->ModeID= (pd->DNode->ModeID & MONITOR_ID_MASK) | (pd->ModeID & (~MONITOR_ID_MASK));
  393.             }*/
  394.             if(pd->ModeID==INVALID_ID) 
  395.                pd->ModeID=pd->DNode->ModeID;
  396.                 
  397.             pd->ModeChanged=TRUE;
  398.           }
  399.           break;
  400.         case 2:
  401. #ifdef ADD_DEBUG_CODE
  402.         if(MPSem->Debug)
  403.         {
  404.           Delay(50*2);
  405.           DKP("Promoting ScreenMode\n");
  406.         }
  407. #endif  
  408.  
  409.           pd->OverscanType  =pd->DNode->OverscanType;
  410.           pd->Width         =pd->DNode->Width;
  411.           pd->Height        =pd->DNode->Height;
  412.       
  413.           if(pd->DNode->Flags & DEPTH)
  414.           {
  415.             pd->Depth=pd->DNode->Depth;
  416.             pd->SetDepth=TRUE;
  417.           }
  418.          
  419.           /* Pick a ModeID */ //                                                                       (4.55.8)
  420.           if(FindDisplayInfo(pd->DNode->ModeID)) // 4.55 @3//                                          (4.55.8)
  421.           {//                                                                                          (4.55.8)
  422.             pd->ModeID        =pd->DNode->ModeID;//                                                    (4.55.8)
  423.           }//                                                                                          (4.55.8)
  424.           else // If the screen Mode doesn't exist try to find a new mode//                            (4.55.8)
  425.           {//                                                                                          (4.55.8)
  426. //            if(V39)//                                                                                  (4.55.8)
  427.             {//                                                                                        (4.55.8)
  428.               pd->ModeID=MyBestModeID(//                                                                 (4.55.8)
  429.                         BIDTAG_DesiredWidth,    pd->Width,//                                           (4.55.8)
  430.                         BIDTAG_DesiredHeight,   pd->Height,//                                          (4.55.8)
  431.                         BIDTAG_NominalWidth,    pd->Width,//                                           (4.55.8)
  432.                         BIDTAG_NominalHeight,   pd->Height,//                                          (4.55.8)
  433.                         (pd->SetDepth ? BIDTAG_Depth:TAG_IGNORE),           pd->Depth,//               (4.55.8)
  434.                         TAG_DONE);//                                                                   (4.55.8)
  435. //                                                                                                     (4.55.8)
  436.             }//                                                                                        (4.55.8)
  437.           }//                                                                                          (4.55.8)
  438.           
  439.           pd->Changed=TRUE;
  440.           break;
  441.           
  442.         case 3:
  443. #ifdef ADD_DEBUG_CODE
  444.         if(MPSem->Debug)
  445.         {
  446.           Delay(50*2);
  447.           DKP("Promoting with Requester\n");
  448.         }
  449. #endif  
  450.           if((pd->SReq=(struct ScreenModeRequester *)AllocAslRequestTags(ASL_ScreenModeRequest,
  451.                       ASLSM_TitleText             ,pd->ScrTitle,
  452.                       ASLSM_DoWidth               ,TRUE ,
  453.                       ASLSM_DoHeight              ,TRUE ,
  454.                       ASLSM_DoOverscanType        ,TRUE ,
  455.                       ASLSM_DoAutoScroll          ,TRUE ,
  456.                       ASLSM_DoDepth               ,pd->DNode->Flags & DEPTH,
  457.                       ASLSM_InitialAutoScroll     ,pd->DNode->AutoScroll,
  458.                       ASLSM_InitialDisplayWidth   ,pd->DNode->Width,
  459.                       ASLSM_InitialDisplayHeight  ,pd->DNode->Height,
  460.                       ASLSM_InitialDisplayID      ,pd->DNode->ModeID,
  461.                       ASLSM_InitialDisplayDepth   ,pd->DNode->Depth,
  462.                       ASLSM_NegativeText          ,GetString(MSG_REQ_USE_DEFAULT),
  463.                       ASLSM_PropertyFlags         ,0,
  464.                       ASLSM_PropertyMask          ,BADMODES,                      
  465.                       TAG_END 
  466.                       )))
  467.           {
  468.             if(AslRequest(pd->SReq,NULL))
  469.             {
  470.               pd->ModeID        =pd->SReq->sm_DisplayID /* | pd->EHB_HAM */; // Can't OR display ID's to get HAM or EHB!
  471.               pd->OverscanType  =pd->SReq->sm_OverscanType;
  472.               pd->Width         =pd->SReq->sm_DisplayWidth;
  473.               pd->Height        =pd->SReq->sm_DisplayHeight;    
  474.               pd->Changed       =TRUE;
  475.               if(pd->DNode->Flags & DEPTH)
  476.               {
  477.                 pd->Depth=pd->SReq->sm_DisplayDepth;
  478.                 pd->SetDepth=TRUE;
  479.               }
  480.             }
  481.             else
  482.             {
  483.               pd->Promote=FALSE;
  484.             }
  485.             FreeAslRequest(pd->SReq);  
  486.           }
  487.           break; 
  488.           
  489.         case MS_PROMOTE_BEST_MODE://                                                                   (4.56.9)
  490. //                                                                                                     (4.56.9)
  491. DEBUG_CODE(DKP("Find Best Mode\n"););//                                                                (4.56.9)
  492. //                                                                                                     (4.56.9)
  493.           pd->OverscanType  =pd->DNode->OverscanType;//                                                (4.56.9)
  494.           pd->Width         =pd->DNode->Width;//                                                       (4.56.9)
  495.           pd->Height        =pd->DNode->Height;//                                                      (4.56.9)
  496.       //                                                                                               (4.56.9)
  497.           if(pd->DNode->Flags & DEPTH)//                                                               (4.56.9)
  498.           {//                                                                                          (4.56.9)
  499.             pd->Depth=pd->DNode->Depth;//                                                              (4.56.9)
  500.             pd->SetDepth=TRUE;//                                                                       (4.56.9)
  501.           }//                                                                                          (4.56.9)
  502.          //                                                                                            (4.56.9)
  503. //          if(V39)//                                                                                    (4.56.9)
  504.           {//             
  505.             ULONG mtag;
  506.             
  507.             if((pd->DNode->ModeID & MONITOR_ID_MASK) == MONITOR_ID_MASK)
  508.             {// fake tag
  509.               mtag=TAG_IGNORE;
  510.             }
  511.             else
  512.             {
  513.               mtag=BIDTAG_MonitorID;
  514.             }
  515.  
  516.             pd->ModeID=MyBestModeID(//                                                                 (4.56.9)
  517.                         mtag,                   (pd->DNode->ModeID & MONITOR_ID_MASK),//               (4.56.9)
  518.                         BIDTAG_DesiredWidth,    pd->Width,//                                           (4.56.9)
  519.                         BIDTAG_DesiredHeight,   pd->Height,//                                          (4.56.9)
  520.                         BIDTAG_NominalWidth,    pd->Width,//                                           (4.56.9)
  521.                         BIDTAG_NominalHeight,   pd->Height,//                                          (4.56.9)
  522.                         (pd->SetDepth ? BIDTAG_Depth:TAG_IGNORE),           pd->Depth,//               (4.56.9)
  523.                         TAG_DONE);//                                                                   (4.56.9)
  524.           }//                                                                                          (4.56.9)
  525.           //                                                                                           (4.56.9)
  526.           pd->Changed=TRUE;//                                                                          (4.56.9)
  527.           break;//                                                                                     (4.56.9)
  528.  
  529.           
  530.       }/* end switch*/
  531.       
  532.       if(!pd->Promote)
  533.       { // 4.52
  534.         RetScreen=OldOpenScreenTagList(ns,TagList,IBase);
  535.         FreeDNode(pd->DNode);
  536.         FreeVec(pd->OpenNode);
  537.         FreeVec(pd);
  538.         
  539. DEBUG_CODE(DKP("  RetVal=%0x08lx (promotion cancelled)\n",RetScreen););
  540.  
  541.         ReleaseSemaphore(&MPSem->ListSem);
  542.         InPatch--;
  543.         
  544.         return(RetScreen);
  545.       }
  546.       
  547.       /**** Setup promoted taglist ****/
  548.       if(pd->Promote)
  549.       {
  550.         pd->SetLook3D   = pd->DNode->Look3D;
  551.         pd->Interleave  =(pd->DNode->Flags & INTERLEAVE) | pd->Interleave;
  552.         pd->ScreenPens  = pd->DNode->Pens;
  553.         pd->AutoScroll  = pd->DNode->AutoScroll;
  554.         pd->BlankBorder = pd->DNode->Flags & DNF_BLANK_BORDER;
  555.         pd->Behind      = pd->DNode->Flags & DNF_BEHIND;
  556.                  
  557.         if( (pd->DNode->Flags & DNF_FORCEPLANAR)        && 
  558.             (pd->Width>0)                               && 
  559.             (pd->Height>0)                              &&
  560.             (!pd->HasCustomBM)                          &&
  561.             (V39)                                       &&
  562.             (pd->Depth>0)  )
  563.         {
  564.     
  565.           if(pd->BitMap=AllocBitMap(pd->Width,pd->Height,pd->Depth,(pd->Interleave?BMF_INTERLEAVED:0)|BMF_STANDARD|BMF_DISPLAYABLE,0))
  566.           {
  567. #ifdef ADD_DEBUG_CODE
  568.             if(MPSem->Debug)
  569.             {               
  570.               ULONG bmflags; 
  571.               
  572.               bmflags=GetBitMapAttr(pd->BitMap,BMA_FLAGS);
  573.               
  574.               DKP("BitMap Flags %8lx\n",bmflags);
  575.             }
  576. #endif  
  577. //            pd->OpenNode->Flags|=ON_BITMAP; // 4.53 @5 can be determined by chaecking on->BitMap
  578.           
  579.             pd->OpenNode->BitMap=pd->BitMap;
  580.             pd->NewTags[pd->TagNumber].ti_Tag=SA_BitMap;
  581.             pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->BitMap;
  582.             pd->TagNumber++;
  583.           }
  584.         }
  585.         
  586.       
  587.         if(pd->Changed && !(pd->HasCustomBM))
  588.         {
  589.           if(pd->Width!=0)
  590.           {
  591.             pd->NewTags[pd->TagNumber].ti_Tag=SA_Width;
  592.             pd->NewTags[pd->TagNumber].ti_Data=pd->Width;
  593.             pd->TagNumber++;
  594.           }
  595.           if(pd->Height!=0)
  596.           {
  597.             pd->NewTags[pd->TagNumber].ti_Tag=SA_Height;
  598.             pd->NewTags[pd->TagNumber].ti_Data=pd->Height;
  599.             pd->TagNumber++;
  600.           }
  601.           
  602.           if(FindTagItem(SA_DClip,TagList))
  603.           { // if it specifies a dclip, i need to override it.
  604.             if(QueryOverscan(pd->ModeID,&pd->ODClip,pd->OverscanType))
  605.             {
  606.               pd->NewTags[pd->TagNumber].ti_Tag=SA_DClip;
  607.               pd->NewTags[pd->TagNumber].ti_Data=(ULONG)&pd->ODClip;
  608.               pd->TagNumber++;
  609.             }
  610.           }
  611.           else
  612.           {
  613.             pd->NewTags[pd->TagNumber].ti_Tag=SA_Overscan;
  614.             pd->NewTags[pd->TagNumber].ti_Data=pd->OverscanType;
  615.             pd->TagNumber++;
  616.           }
  617.         }
  618.       
  619.         if(pd->ModeChanged || pd->Changed)
  620.         {
  621.           pd->NewTags[pd->TagNumber].ti_Tag=SA_DisplayID;
  622.           pd->NewTags[pd->TagNumber].ti_Data=pd->ModeID;
  623.           pd->TagNumber++;
  624.         }
  625.     
  626.         if(pd->DNode->Flags & SHAREPENS)
  627.         {
  628.           pd->NewTags[pd->TagNumber].ti_Tag=SA_SharePens;
  629.           pd->NewTags[pd->TagNumber].ti_Data=TRUE;
  630.           pd->TagNumber++;
  631.         }
  632.     
  633.         if(pd->SetDepth && !(pd->HasCustomBM) && !(pd->EHB_HAM))
  634.         {
  635.           pd->NewTags[pd->TagNumber].ti_Tag=SA_Depth;
  636.           pd->NewTags[pd->TagNumber].ti_Data=pd->Depth;
  637.           pd->TagNumber++;
  638.     
  639.         }
  640.     
  641.         
  642.         if((pd->DNode->Flags & DNF_PALETTE) && pd->DNode->Palette && pd->DNode->Colors)
  643.         {
  644.           if(V39)
  645.           {    
  646.             pd->Colors32[0]=pd->DNode->Colors<<16;
  647.             CopyMemQuick(pd->DNode->Palette,&pd->Colors32[1],pd->DNode->Colors*3*sizeof(ULONG));
  648.             pd->Colors32[pd->DNode->Colors*3+2]=0;
  649.             
  650.             pd->NewTags[pd->TagNumber].ti_Tag=SA_Colors32;
  651.             pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->Colors32;
  652.             pd->TagNumber++;
  653.           }
  654.           else
  655.           {
  656.             ULONG c;
  657.       
  658.             for(c=0;c<pd->DNode->Colors;c++)
  659.             {
  660.               pd->ColorSpec[c].ColorIndex=c;
  661.               pd->ColorSpec[c].Red   =pd->DNode->Palette[c].Red>>28;
  662.               pd->ColorSpec[c].Green =pd->DNode->Palette[c].Green>>28;
  663.               pd->ColorSpec[c].Blue  =pd->DNode->Palette[c].Blue>>28;
  664.             }
  665.             pd->ColorSpec[c].ColorIndex=-1;
  666.             
  667.             pd->NewTags[pd->TagNumber].ti_Tag=SA_Colors; 
  668.             pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->ColorSpec;
  669.             pd->TagNumber++;
  670.           }
  671.         }
  672.     
  673.         switch(pd->DNode->FontType)
  674.         {
  675.           case SFONT_SYS:
  676.             if(ns) ns->Font=0;
  677.             pd->NewTags[pd->TagNumber].ti_Tag=SA_SysFont;
  678.             pd->NewTags[pd->TagNumber].ti_Data=1;
  679.             pd->TagNumber++;
  680.             break;
  681.           case SFONT_MP:
  682.             if(pd->DNode->Font.tta_Name)
  683.             {
  684. //              if(pd->OpenNode=AllocOpenNode(pd->OpenNode))
  685.               {
  686.                 pd->OpenNode->Flags|=ON_FONT;
  687.               
  688.                 pd->NewTags[pd->TagNumber].ti_Tag  =SA_Font;
  689.                 pd->NewTags[pd->TagNumber].ti_Data =(ULONG)&pd->OpenNode->TA;
  690.                 pd->TagNumber++;
  691.       
  692.                 if(pd->DNode->Flags & FIXASPECT && pd->ModeID != -1)
  693.                 {
  694.                   if(GetDisplayInfoData(NULL,(UBYTE *)&pd->DispInfo,sizeof(struct DisplayInfo),DTAG_DISP,pd->ModeID))
  695.                   {
  696.                     fonttags[0].ti_Data=(ULONG)pd->DispInfo.Resolution.x|(((ULONG)pd->DispInfo.Resolution.y)<<16);
  697.                     pd->DNode->Font.tta_Style |= FSF_TAGGED;
  698.                     pd->DNode->Font.tta_Tags   =fonttags;
  699.                   }
  700.                 }
  701.                 CloneTextAttr(&pd->DNode->Font,&pd->OpenNode->TA);
  702.       
  703.                 pd->DNode->Font.tta_Style &= (~FSF_TAGGED);
  704.                 pd->DNode->Font.tta_Tags=NULL;
  705.               }
  706.             }
  707.             break;
  708.         }
  709.     
  710.         if(pd->DNode->PubOptions==1 && pd->DNode->PubName)
  711.         {
  712.           ULONG error=FALSE;
  713.           struct TagItem badtags[]=
  714.           {
  715.             SA_BitMap,    1<<0,
  716. //          SA_PubName,   1<<1,
  717.             SA_PubSig,    1<<2,
  718.             SA_PubTask,   1<<3,
  719.             SA_BackFill,  1<<4,
  720.             TAG_DONE,     0
  721.           };
  722.           
  723.           if(TagList) error =PackBoolTags(0,TagList,badtags);
  724.           if(ns)      error|=(ns->Type & CUSTOMBITMAP);
  725.           
  726.           if(error==0)
  727.           {
  728. //            if(pd->OpenNode=AllocOpenNode(pd->OpenNode))
  729.             {
  730.               struct OpenNode *won;
  731.               UBYTE number[8];
  732.               ULONG cnt=1,len;
  733.               
  734.               strncpy(pd->OpenNode->PubName,pd->DNode->PubName,MAXPUBSCREENNAME);
  735.               pd->OpenNode->PubName[MAXPUBSCREENNAME]=0;
  736.               len=strlen(pd->OpenNode->PubName);
  737.               len=min(len,MAXPUBSCREENNAME-9);
  738.               
  739.               ObtainSemaphore(&MPSem->OpenListSem);
  740.               
  741.               won=(struct OpenNode *)MPSem->OpenList.lh_Head;
  742.               while(won->on_Node.ln_Succ)
  743.               {
  744.                 if(cnt > 1)   
  745.                 {
  746.                   number[0]='.';
  747.                   stci_d(&number[1],cnt);        
  748.                   pd->OpenNode->PubName[len]=0;
  749.                   strncat(pd->OpenNode->PubName,number,MAXPUBSCREENNAME);
  750.                   pd->OpenNode->PubName[MAXPUBSCREENNAME]=0;
  751.                 }
  752.                 
  753.                 if(0==strcmp(pd->OpenNode->PubName,won->PubName))
  754.                 {
  755.                   won=(struct OpenNode *)MPSem->OpenList.lh_Head;
  756.                   cnt++;
  757.                 }
  758.                 else
  759.                   won=(struct OpenNode *)won->on_Node.ln_Succ;
  760.               }
  761.               
  762.               ReleaseSemaphore(&MPSem->OpenListSem);
  763.               
  764.               pd->OpenNode->ScreenTitle=CopyString(pd->ScrTitle,MEMF_PUBLIC); 
  765.               // Name cloned, when app CloseScreen's this title replaces the app supplied one
  766.               
  767.               pd->OpenNode->PubName[MAXPUBSCREENNAME]=0;
  768.               pd->OpenNode->Flags|= ON_PUBLIC | ON_OPEN;
  769.               
  770.               pd->NewTags[pd->TagNumber].ti_Tag=SA_Title;//                                            (4.58.1)
  771.               pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->OpenNode->ScreenTitle;//                   (4.58.1)
  772.               pd->TagNumber++;//                                                                       (4.58.1)
  773.       
  774.               pd->NewTags[pd->TagNumber].ti_Tag=SA_PubName;
  775.               pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->OpenNode->PubName;
  776.               pd->TagNumber++;
  777.           
  778.               pd->NewTags[pd->TagNumber].ti_Tag=SA_PubSig;
  779.               pd->NewTags[pd->TagNumber].ti_Data=PublicSignal;
  780.               pd->TagNumber++;
  781.               
  782.               pd->NewTags[pd->TagNumber].ti_Tag=SA_PubTask;
  783.               pd->NewTags[pd->TagNumber].ti_Data=(ULONG)MPTask;
  784.               pd->TagNumber++;
  785.               
  786.               
  787.               if(!(pd->OpenNode->Flags & ON_FONT))
  788.               {
  789.                 struct TTextAttr *ot=NULL;
  790.                 
  791.                 if(ns)  ot=(struct TTextAttr *)ns->Font;          
  792.                 ot=(struct TTextAttr *)GetTagData(SA_Font,(ULONG)ot,TagList);
  793.                 
  794.                 if(ot)
  795.                 {
  796.                   pd->OpenNode->Flags|=ON_FONT;
  797.       
  798.                   CloneTextAttr(ot,&pd->OpenNode->TA);
  799.       
  800.                   pd->NewTags[pd->TagNumber].ti_Tag =SA_Font;
  801.                   pd->NewTags[pd->TagNumber].ti_Data=(ULONG)&pd->OpenNode->TA;
  802.                   pd->TagNumber++;
  803.                 }
  804.               }
  805.             }
  806.           }
  807.         }
  808.       } /* end - if(pd->Promote) */
  809.     }/* end - if(!pd->IsWorkbench) */
  810.     
  811.     if(pd->IsWorkbench) 
  812.     { /* Yes, this is the Workbench screen */
  813. //      if(pd->OpenNode=AllocOpenNode(pd->OpenNode))
  814.         pd->OpenNode->Flags|=ON_WORKBENCH;
  815.     }
  816.   
  817.     if(pd->Promote)
  818.     {
  819.       if(pd->SetLook3D)
  820.       {
  821.         LONG dp;
  822.         
  823.         if(pd->DNode->Flags & DNF_3D_DEFAULT)
  824.         {
  825.           if(V39 && pd->Depth>1 && MPSem->PPrefsSet)
  826.           {
  827.             /* Use 4 color palette from prefs */
  828.             for(dp=0;dp<DRIPENS;dp++)
  829.               pd->DriPens[dp]=MPSem->PPrefs.pap_4ColorPens[dp] & 0xff;
  830.             pd->DriPens[dp]=~0;
  831.           }
  832.           else
  833.             pd->DriPens[0]=~0;
  834.         }
  835.         else
  836.         {
  837.           for(dp=0;dp<DRIPENS;dp++)
  838.             pd->DriPens[dp]=pd->DNode->Pens[dp] & 0xff;
  839.           pd->DriPens[dp]=~0;
  840.         }
  841.         
  842.         pd->NewTags[pd->TagNumber].ti_Tag=SA_Pens;
  843.         pd->NewTags[pd->TagNumber].ti_Data=(ULONG)pd->DriPens;
  844.         pd->TagNumber++;
  845.         /*
  846.         if(pd->Depth==1)
  847.         {
  848.           pd->Depth=2;  // This nolonger works
  849.           pd->SetDepth=TRUE;
  850.           //  pd->NewTags[pd->TagNumber].ti_Tag=SA_Depth;
  851.           //  pd->NewTags[pd->TagNumber].ti_Data=2;
  852.           //   pd->TagNumber++;
  853.         }*/
  854.       }
  855.     
  856.       if(pd->AutoScroll)
  857.       {
  858.         pd->NewTags[pd->TagNumber].ti_Tag=SA_AutoScroll;
  859.         pd->NewTags[pd->TagNumber].ti_Data=TRUE;
  860.         pd->TagNumber++;
  861.       }
  862.  
  863.       if(pd->Behind)
  864.       {
  865.         pd->NewTags[pd->TagNumber].ti_Tag=SA_Behind;
  866.         pd->NewTags[pd->TagNumber].ti_Data=TRUE;
  867.         pd->TagNumber++;
  868.       }    
  869.       
  870.       if(pd->DNode->CenterFlags)
  871.       {    
  872.         if(QueryOverscan(pd->ModeID,&pd->ODClip,pd->OverscanType))
  873.         //if(GetDisplayInfoData(NULL,(UBYTE *)&pd->DimInfo,sizeof(struct DimensionInfo),DTAG_DIMS,pd->ModeID))
  874.         {
  875.           if(pd->DNode->CenterFlags & 1)
  876.           {
  877.             if(pd->Width>-1 && pd->ODClip.MaxX > pd->ODClip.MinX)
  878.             {
  879. #ifdef ADD_DEBUG_CODE
  880.               if(MPSem->Debug)
  881.               {
  882.                 DKP("  ODClip.MinX=%ld  ODClip.MaxX=%ld  Width=%ld\n",pd->ODClip.MinX,pd->ODClip.MaxX,pd->Width);
  883.               }
  884. #endif
  885.  
  886.               pd->NewTags[pd->TagNumber].ti_Tag=SA_Left;
  887.               pd->NewTags[pd->TagNumber].ti_Data=((pd->ODClip.MaxX-pd->ODClip.MinX)-pd->Width)/2+pd->ODClip.MinX;
  888.               pd->TagNumber++;
  889.             }
  890.           }
  891.           if(pd->DNode->CenterFlags & 2)
  892.           {
  893.             if(pd->Height>-1 && pd->ODClip.MaxX > pd->ODClip.MinX)
  894.             {
  895. #ifdef ADD_DEBUG_CODE
  896.               if(MPSem->Debug)
  897.               {
  898.                 DKP("  ODClip.MinY=%ld  ODClip.MaxY=%ld  Height=%ld\n",pd->ODClip.MinY,pd->ODClip.MaxY,pd->Height);
  899.               }
  900. #endif
  901.               
  902.               pd->NewTags[pd->TagNumber].ti_Tag=SA_Top;
  903.               pd->NewTags[pd->TagNumber].ti_Data=((pd->ODClip.MaxY-pd->ODClip.MinY)-pd->Height)/2+pd->ODClip.MinY;
  904.               pd->TagNumber++;
  905.             }
  906.           }
  907.           
  908. #ifdef ADD_DEBUG_CODE         
  909.           PrintOverscanInfo(pd);
  910. #endif
  911.           
  912.         }
  913.       }
  914.        
  915.       if(pd->DNode->Flags & SCRHOTKEY && pd->DNode->HotKey)
  916.       {
  917. //        if(pd->OpenNode=AllocOpenNode(pd->OpenNode))
  918.         {
  919.           if(pd->OpenNode->HotKey=AllocVec(strlen(pd->DNode->HotKey)+1,MEMF_CLEAR|MEMF_PUBLIC))
  920.           {
  921.             strcpy(pd->OpenNode->HotKey,pd->DNode->HotKey);
  922.             pd->OpenNode->Cx=AddHotKey(Broker,BrokerPort,pd->OpenNode->HotKey,(ULONG)pd->OpenNode);
  923.           }
  924.         }
  925.       }
  926.       
  927.     
  928.       if(pd->Interleave && !(pd->HasCustomBM) && !pd->BitMap)
  929.       {
  930.         pd->NewTags[pd->TagNumber].ti_Tag=SA_Interleaved;
  931.         pd->NewTags[pd->TagNumber].ti_Data=TRUE;
  932.         pd->TagNumber++;
  933.       }
  934.         
  935.       pd->NewTags[pd->TagNumber].ti_Tag=SA_MinimizeISG; /*** just a little extra for v40 ***/
  936.       pd->NewTags[pd->TagNumber].ti_Data=TRUE;
  937.       pd->TagNumber++;
  938.     
  939.       
  940.       /**** End Setup TagList ****/
  941.       
  942. //      if(pd->OpenNode)
  943.       {
  944.         if(pd->OpenNode->Flags & ON_FONT)
  945.           pd->TextFont=OpenDiskFont((struct TextAttr *)&pd->OpenNode->TA);
  946.       }
  947.     } /* end - if(pd->Promote) */
  948.   
  949.   
  950.     if(TagList)
  951.     {
  952.       pd->NewTags[pd->TagNumber].ti_Tag=TAG_MORE;
  953.       pd->NewTags[pd->TagNumber].ti_Data=(ULONG)TagList;
  954.     }
  955.     else
  956.     {
  957.       pd->NewTags[pd->TagNumber].ti_Tag=TAG_DONE;
  958.       pd->NewTags[pd->TagNumber].ti_Data=0;
  959.     }
  960.   
  961. #ifdef ADD_DEBUG_CODE  
  962.     if(MPSem->Debug)
  963.     {
  964.       Delay(50*1);
  965.       DKP("  %ld new tags\n",pd->TagNumber);
  966.       DKP("  New TagList\n");
  967.       PrintTags(pd->NewTags);
  968.      
  969.       DKP("  Opening\n");
  970.     }
  971. #endif
  972.   
  973.     RetScreen=OldOpenScreenTagList(ns,pd->NewTags,IBase);
  974.     if(ns)
  975.     {
  976.       ns->Font=pd->StoredFont;
  977.     }
  978.   
  979.     if(RetScreen)
  980.     {
  981.       pd->OpenNode->Screen=RetScreen;
  982.  
  983. /*      
  984.       // CyberKludge
  985.       if(pd->OpenNode->BitMap)
  986.       {
  987.         RetScreen->BitMap=*pd->OpenNode->BitMap;  
  988.         RetScreen->RastPort.BitMap=pd->OpenNode->BitMap;
  989.       }
  990.       
  991.       if(pd->HasCustomBM)
  992.       {
  993.         RetScreen->BitMap=*(struct BitMap *)pd->HasCustomBM;  
  994.         RetScreen->RastPort.BitMap=pd->HasCustomBM;
  995.       }     
  996. */      
  997.       
  998.       if(pd->BlankBorder)
  999.       {
  1000.         ULONG vrt;
  1001.         VideoControlTags(RetScreen->ViewPort.ColorMap,
  1002.                           VTAG_BORDERBLANK_SET, TRUE,
  1003.                           VTAG_IMMEDIATE        ,&vrt,
  1004.                           TAG_DONE);
  1005.         MakeScreen(RetScreen);
  1006.       }
  1007.  
  1008.       mpObtainPens(pd);
  1009.       
  1010.       if(pd->OpenNode) // 4.53 @6
  1011.       {
  1012.         SendMPMsg(MP_SCREENOPENED,0,pd->OpenNode); 
  1013.       }
  1014.   
  1015. #ifdef ADD_DEBUG_CODE  
  1016.       if(MPSem->Debug)
  1017.       {
  1018.         Delay(50*1);
  1019.         DKP("  Screen Addr %8lx\n",RetScreen);
  1020.       }
  1021. #endif
  1022.  
  1023.       /**************/    
  1024.       
  1025.       if(pd->OpenNode->Flags & ON_FONT)
  1026.         if(pd->TextFont)
  1027.           CloseFont(pd->TextFont);
  1028.       
  1029.       if(pd->OpenNode->Flags & ON_PUBLIC)
  1030.       {
  1031.         PubScreenStatus(RetScreen,0);
  1032. //        pd->OpenNode->PubScreenLock=LockPubScreen(pd->OpenNode->PubName);
  1033. /*
  1034. #ifdef ADD_DEBUG_CODE  
  1035.         if(MPSem->Debug)
  1036.         {
  1037.           DKP("PubScreenLock=%8lx\n",pd->OpenNode->PubScreenLock);
  1038.         }
  1039. #endif
  1040. */
  1041.       }
  1042.           
  1043.       ObtainSemaphore(&MPSem->OpenListSem);
  1044.       AddHead(&MPSem->OpenList,(struct Node *)pd->OpenNode);
  1045.       ReleaseSemaphore(&MPSem->OpenListSem);
  1046.  
  1047. DEBUG_CODE(DKP("  RetVal=%0x08lx (promoted)\n",RetScreen););      
  1048.  
  1049.     }
  1050.     else
  1051.     {
  1052.       FreeOpenNode(pd->OpenNode);
  1053.       if(!GetTagData(SA_ModeProNode,0,TagList))//                                                      (4.62.8)
  1054.       {
  1055.         RetScreen=OldOpenScreenTagList((struct ExtNewScreen *)ns,TagList,IBase);
  1056.       }
  1057.       
  1058. DEBUG_CODE(DKP("  RetVal=%0x08lx (promotion failed, opened unpromoted)\n",RetScreen););
  1059.     }
  1060.     
  1061.     FreeVec(pd);
  1062.     
  1063.     ReleaseSemaphore(&MPSem->ListSem);
  1064.     InPatch--;
  1065.     
  1066.     return(RetScreen);
  1067.   }
  1068. //  ReleaseSemaphore(&MPSem->NodeSem); 
  1069.   ReleaseSemaphore(&MPSem->ListSem);
  1070.   InPatch--;
  1071.   
  1072. DEBUG_CODE(DKP("  RetVal=%0x08lx (failed)\n",0););      
  1073.   
  1074.   return(0);
  1075. }
  1076.  
  1077.  
  1078. /*
  1079. void CatchDNode(ULONG Dest, UBYTE *Name, struct DefaultNode *SrcNode)
  1080. {
  1081.   struct DefaultNode *dnode;
  1082.   LONG l;
  1083.   
  1084.   if(dnode=AllocDefaultNode(Name))
  1085.   {
  1086.     dnode->Type         =Dest;
  1087.     dnode->Width        =SrcNode->Width;
  1088.     dnode->Height       =SrcNode->Height;
  1089.     dnode->AutoScroll   =SrcNode->AutoScroll;
  1090.     dnode->ModeSelect   =0;
  1091.     dnode->ModeID       =SrcNode->ModeID;
  1092.     dnode->OverscanType =SrcNode->OverscanType;
  1093.     dnode->Look3D       =SrcNode->Look3D;
  1094.     dnode->Flags        =SrcNode->Flags;
  1095.     dnode->Depth        =SrcNode->Depth;
  1096. /******* change to <= */
  1097.     for(l=0;l<DRIPENS;l++)
  1098.       dnode->Pens[l]      =SrcNode->Pens[l];
  1099.     
  1100.     PutMsg(CatchPort,(struct Message *)dnode);
  1101.   }
  1102.   return;
  1103. }
  1104. */
  1105.  
  1106. /* Go into forced edit mode, user must edit this node before returning */
  1107. struct DefaultNode *ForceEdit(struct DefaultNode *DNode)
  1108. {
  1109.   struct DefaultNode *retval;
  1110.   struct MsgPort *rport;
  1111.   struct MPMessage *mpm;
  1112.  
  1113.   retval=0;
  1114.   
  1115.   if(rport=CreateMsgPort())
  1116.   {
  1117.     if(mpm=AllocVec(sizeof(*mpm),MEMF_PUBLIC|MEMF_CLEAR))
  1118.     {
  1119.       if(ShowGUI())//                                                                                  (4.62.14)
  1120.       {//                                                                                              (4.62.14)
  1121.         /* Send ForcedEdit node to MPP */
  1122.         mpm->Data=DNode;
  1123.         mpm->Command=MP_FORCEDEDIT;
  1124.         mpm->mp_Message.mn_Length=sizeof(struct MPMessage);
  1125.         mpm->mp_Message.mn_ReplyPort=rport;
  1126.  
  1127.         /* send message to ForceEditPort owner */
  1128. DEBUG_CODE(DKP("FE()-sending MP_FORCEDEDIT\n"););
  1129.         ObtainSemaphore(&MPSem->PortSem);
  1130.         PutMsg(&MPSem->PrefsToDoPort,(struct Message *)mpm);//                                         (4.62.11)
  1131.         ReleaseSemaphore(&MPSem->PortSem);
  1132.         
  1133. DEBUG_CODE(DKP("FE()-Waiting for replies\n"););
  1134.         WaitForReply((struct Message *)mpm);
  1135. DEBUG_CODE(DKP("FE()-Reply received\n"););        
  1136.  
  1137.         switch(mpm->Code)
  1138.         {
  1139.           case MPFE_USEDELETE:
  1140.             retval=DNode; // return DNode for use.
  1141.             break;
  1142.             
  1143.           case MPFE_NEVER:
  1144.             DNode->Flags=DNF_NEVER_PROMOTE;  // Set flag and give to MP
  1145.             PutMsg(CatchPort,(struct Message *)DNode);
  1146.             retval =0;
  1147.             break;
  1148.             
  1149.           case MPFE_SAVEUSE:
  1150.             {
  1151.               retval =DNode;
  1152.               if(DNode  =DupDNode(retval))   /* Duplicate, give copy to MP and then use orignal for promotion */
  1153.               {
  1154.                 PutMsg(CatchPort,(struct Message *)DNode);
  1155.               }
  1156.             }
  1157.             break;
  1158.             
  1159.           case MPFE_CANCEL:
  1160.           default:
  1161.             /* Delete the new node */
  1162.             FreeDNode(DNode);
  1163.         }//END SWITCH
  1164.       }
  1165.       FreeVec(mpm);
  1166.     }
  1167.     DeleteMsgPort(rport);
  1168.   }
  1169.   return(retval);
  1170. }
  1171.  
  1172. void WaitForReply(struct Message *Msg)
  1173. {
  1174.   struct Message *m;
  1175.   struct MsgPort *port;
  1176.   
  1177.   m=0;
  1178.   port=Msg->mn_ReplyPort;
  1179.   
  1180.   while(m!=Msg)
  1181.   {
  1182.     WaitPort(port);
  1183.     
  1184.     m=GetMsg(port);
  1185.   }
  1186. }
  1187.  
  1188. // 4.53 @7 renamed, parameter renamed
  1189. BOOL SendMPMsg(ULONG Command, ULONG Code, APTR Data)
  1190. {
  1191.   struct MsgPort  *mport;
  1192.   struct MPMessage mpm;
  1193.  
  1194.   if(mport=CreateMsgPort())
  1195.   {
  1196.     mpm.mp_Message.mn_ReplyPort=mport;
  1197.     mpm.mp_Message.mn_Length=sizeof(mpm);
  1198.     mpm.Command = Command;
  1199.     mpm.Code    = Code;
  1200.     mpm.Data    = Data;
  1201.  
  1202.     PutMsg(MPSem->DaemonPort,(struct Message *)&mpm);
  1203.  
  1204.     WaitForReply((struct Message *)&mpm);
  1205.  
  1206.     DeleteMsgPort(mport);
  1207.     return(1);
  1208.   }
  1209.   return(0);
  1210. }
  1211.  
  1212. /*
  1213.   
  1214.       if(pd->DNode->Flags & SHAREPENS && 
  1215.          pd->DNode->LockedPens        && 
  1216.          V39)
  1217.       {
  1218.         UBYTE *str,state=0,done=FALSE;
  1219.         WORD num=0,num1=0,num2;
  1220.         struct ColorMap *cm;
  1221.         
  1222.         cm=RetScreen->ViewPort.ColorMap;
  1223.         
  1224.         str=pd->DNode->LockedPens;
  1225.         
  1226.         while(!done)
  1227.         {
  1228.           if(!*str) done=TRUE;
  1229.           
  1230.           if(*str>='0' && *str<='9')
  1231.           {
  1232.             if(state==0)
  1233.               state=1;
  1234.             num=0;
  1235.             while(*str>='0' && *str<='9')
  1236.             {
  1237.               num*=10;
  1238.               num+=*str - '0';
  1239.               str++;
  1240.             }
  1241.             
  1242.             switch(state)
  1243.             {
  1244.               case 1:
  1245. #ifdef ADD_DEBUG_CODE  
  1246.                 if(MPSem->Debug)
  1247.                 {
  1248.                   DKP("  obtaining pen %ld\n",num);
  1249.                 }
  1250. #endif        
  1251.                 if(!pd->OpenNode->ObtainedPens[num])
  1252.                 {
  1253.                   if(-1!=ObtainPen(cm,num,0,0,0, PEN_EXCLUSIVE | PEN_NO_SETCOLOR)))
  1254.                     pd->OpenNode->ObtainedPens[num]=1;
  1255.                 }
  1256.                 break;
  1257.               case 2:
  1258.                 for(num2=num1+1;num2<=num;num2++)
  1259.                 {
  1260. #ifdef ADD_DEBUG_CODE  
  1261.                   if(MPSem->Debug)
  1262.                   {
  1263.                     DKP("  obtaining pen %ld\n",num2);
  1264.                   }
  1265. #endif
  1266.                   if(!pd->OpenNode->ObtainedPens[num2])
  1267.                   {
  1268.                     if(-1!=ObtainPen(cm,num2,0,0,0, PEN_EXCLUSIVE | PEN_NO_SETCOLOR))
  1269.                       pd->OpenNode->ObtainedPens[num2]=1;
  1270.                   }
  1271.                 }
  1272.                 break;
  1273.             }
  1274.             state=0;
  1275.            
  1276.           }
  1277.           
  1278.           if(*str==' ')
  1279.             for(;*str==' ';str++);
  1280.           else
  1281.             if(*str=='-')
  1282.             {
  1283.               num1=num;
  1284.               state=2;
  1285.               str++;
  1286.             }
  1287.             else
  1288.               str++;
  1289.         }
  1290.       }
  1291.       
  1292.       */
  1293.  
  1294.  
  1295. void DoNothing(ULONG *L)
  1296. {
  1297. }
  1298.  
  1299. #include <dos/dosextens.h>
  1300.  
  1301. LONG MyGetProgramName(STRPTR Buffer, LONG Len)//                                                       (4.56.6)
  1302. {//                                                                                                    (4.56.6)
  1303.   LONG bp,l;//                                                                                         (4.56.6)
  1304.   struct Process *p;//                                                                                 (4.56.6)
  1305.   struct CommandLineInterface *cli;//                                                                  (4.56.6)
  1306.   UBYTE *name;//                                                                                       (4.56.6)
  1307. //                                                                                                     (4.56.6)
  1308.   l=0;//                                                                                               (4.56.6)
  1309. //                                                                                                     (4.56.6)
  1310.   p=(struct Process *)FindTask(0);//                                                                   (4.56.6)
  1311.  
  1312.   Buffer[0]=0;                              // Add NULL //                                         (4.56.6)
  1313.  
  1314.   if(p->pr_Task.tc_Node.ln_Type==NT_PROCESS)//                                                         (4.56.6)
  1315.   {//                                                                                                  (4.56.6)
  1316.     // We are a process//                                                                              (4.56.6)
  1317.     if(bp=(p->pr_CLI<<2))//                                                                            (4.56.6)
  1318.     {//                                                                                                (4.56.6)
  1319.       cli=(struct CommandLineInterface *)bp;//                                                         (4.56.6)
  1320.       if(name=(UBYTE *)(cli->cli_CommandName<<2))             //                                       (4.56.6)
  1321.       {//                                                                                              (4.56.6)
  1322.         for(l=0;l<name[0] && l<Len-1;l++)       // Copy BSTR to CSTR string//                          (4.56.6)
  1323.         {//                                                                                            (4.56.6)
  1324.           Buffer[l]=name[l+1];  //                                                                     (4.56.6)
  1325.         }//                                                                                            (4.56.6)
  1326.         Buffer[l]=0;                              // Add NULL //                                         (4.56.6)//  (4.59.1)
  1327.       }//                                                                                              (4.56.6)
  1328.     }//                                                                                                (4.56.6)
  1329.   }//
  1330. DEBUG_CODE(DKP("MyGetProgramName=%s\n",Buffer););
  1331.   return(l);//                                                                                         (4.56.6)
  1332. }//                                                                                                    (4.56.6)
  1333.  
  1334. /*
  1335. /* Go into forced edit mode, user must edit this node before returning */
  1336. struct DefaultNode *ForceEdit(struct DefaultNode *DNode)
  1337. {
  1338.   struct DefaultNode *retval;
  1339.   struct MsgPort *rport;
  1340.   struct MPMessage *showgui,*mpm,*copympm;
  1341.  
  1342.   retval=0;
  1343.   
  1344.   if(rport=CreateMsgPort())
  1345.   {
  1346.     if(showgui=AllocVec(sizeof(*showgui),MEMF_PUBLIC|MEMF_CLEAR))
  1347.     {
  1348.       if(copympm=mpm=AllocVec(sizeof(struct MPMessage),MEMF_PUBLIC|MEMF_CLEAR))
  1349.       {
  1350.         /*
  1351.         /* Instruct MP to open editor */
  1352.         showgui->Command=MP_SHOWGUI;
  1353.         showgui->mp_Message.mn_Length=sizeof(struct MPMessage);
  1354.         showgui->mp_Message.mn_ReplyPort=rport;
  1355. DEBUG_CODE(DKP("FE()-sending MP_SHOWGUI\n"););
  1356.         PutMsg(MPSem->DaemonPort,(struct Message *)showgui);//                                           (4.62.12)
  1357.         */
  1358.         ShowGUI();
  1359.         
  1360.         /* Send ForcedEdit node to MPP */
  1361.         mpm->Data=DNode;
  1362.         mpm->Command=MP_FORCEDEDIT;
  1363.         mpm->mp_Message.mn_Length=sizeof(struct MPMessage);
  1364.         mpm->mp_Message.mn_ReplyPort=rport;
  1365.  
  1366.         /* send message to ForceEditPort owner */
  1367. DEBUG_CODE(DKP("FE()-sending MP_FORCEDEDIT\n"););
  1368.         ObtainSemaphore(&MPSem->PortSem);
  1369.         PutMsg(&MPSem->PrefsToDoPort,(struct Message *)mpm);//                                         (4.62.11)
  1370.         ReleaseSemaphore(&MPSem->PortSem);
  1371.         
  1372.         mpm=showgui=0;
  1373.         
  1374.         while(mpm==0 && showgui==0)
  1375.         {
  1376.           struct MPMessage *m;
  1377.           
  1378. DEBUG_CODE(DKP("FE()-Waiting for replies\n"););
  1379.           WaitPort(rport);
  1380.           m=(APTR)GetMsg(rport);
  1381.           switch(m->Command)
  1382.           {
  1383.             case MP_FORCEDEDIT:
  1384. DEBUG_CODE(DKP("FE()-recieved MP_FORCEDEDIT\n"););
  1385.               mpm=m;
  1386.               break;
  1387.             case MP_SHOWGUI:
  1388. DEBUG_CODE(DKP("FE()-recieved MP_SHOWGUI\n"););
  1389.               showgui=m;
  1390.               if(showgui->Code==0)
  1391.               {
  1392.                 // if showgui fails, remove mpm from the todo port and cancel it
  1393.                 ObtainSemaphore(&MPSem->PortSem);
  1394.                 Remove((struct Node *)copympm);
  1395.                 mpm=copympm;
  1396.                 mpm->Code=MPFE_CANCEL;
  1397.                 ReleaseSemaphore(&MPSem->PortSem);
  1398.               }
  1399.               break;
  1400.           }
  1401.         }
  1402.         
  1403.         switch(mpm->Code)
  1404.         {
  1405.           case MPFE_USEDELETE:
  1406.             retval=DNode; // return DNode for use.
  1407.             break;
  1408.             
  1409.           case MPFE_NEVER:
  1410.             DNode->Flags=DNF_NEVER_PROMOTE;  // Set flag and give to MP
  1411.             PutMsg(CatchPort,(struct Message *)DNode);
  1412.             retval =0;
  1413.             break;
  1414.             
  1415.           case MPFE_SAVEUSE:
  1416.             {
  1417.               retval =DNode;
  1418.               if(DNode  =DupDNode(retval))   /* Duplicate, give copy to MP and then use orignal for promotion */
  1419.               {
  1420.                 PutMsg(CatchPort,(struct Message *)DNode);
  1421.               }
  1422.             }
  1423.             break;
  1424.             
  1425.           case MPFE_CANCEL:
  1426.           default:
  1427.             /* Delete the new node */
  1428.             FreeDNode(DNode);
  1429.         }//END SWITCH
  1430.         FreeVec(mpm);
  1431.       }
  1432.       FreeVec(showgui);
  1433.     }
  1434.     DeleteMsgPort(rport);
  1435.   }
  1436.   return(retval);
  1437. }
  1438.  
  1439. */